package com.yidiandao.business.ui.widget.listview.viewholder;

import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.ui.widget.view.RatioLayout;
import com.yidiandao.business.ui.widget.view.TimerLayout;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.TextRenderUtils;
import com.yidiandao.business.utils.UIUtils;

/** 限时抢购Item-ViewHolder */
public class HomeFlashSaleHolder extends ViewHolder {

    public TextView tvMore;
    public TimerLayout timerLayout1;
    public ImageView ivImage1;
    public TextView tvTitle1;
    public TextView tvNewPrice1;
    public TextView tvDeprecatePrice1;
    public LinearLayout limitLayout1;
    public RelativeLayout rootState1;
    public TextView tvState1;
    public RatioLayout ratioLayout1;
    public TimerLayout toStartTimerLayout1;

    public TimerLayout timerLayout2;
    public ImageView ivImage2;
    public TextView tvTitle2;
    public TextView tvNewPrice2;
    public TextView tvDeprecatePrice2;
    public LinearLayout limitLayout2;
    public RelativeLayout rootState2;
    public TextView tvState2;
    public RatioLayout ratioLayout2;
    public TimerLayout toStartTimerLayout2;

    public TimerLayout timerLayout3;
    public ImageView ivImage3;
    public TextView tvTitle3;
    public TextView tvNewPrice3;
    public TextView tvDeprecatePrice3;
    public LinearLayout limitLayout3;
    public RelativeLayout rootState3;
    public TextView tvState3;
    public RatioLayout ratioLayout3;
    public TimerLayout toStartTimerLayout3;

    private ImageView ivTitle;

    @Override
    protected void initView(View rootView) {
        tvMore = (TextView) rootView.findViewById(R.id.tv_enter);

        timerLayout1 = (TimerLayout) rootView.findViewById(R.id.timer_layout_1);
        ivImage1 = (ImageView) rootView.findViewById(R.id.iv_image_1);
        tvTitle1 = (TextView) rootView.findViewById(R.id.tv_title_1);
        tvNewPrice1 = (TextView) rootView.findViewById(R.id.tv_new_price_1);
        tvDeprecatePrice1 = (TextView) rootView.findViewById(R.id.tv_deprecate_price_1);
        limitLayout1 = (LinearLayout) rootView.findViewById(R.id.limit_1);
        rootState1 = (RelativeLayout) rootView.findViewById(R.id.root_state_1);
        tvState1 = (TextView) rootView.findViewById(R.id.tv_state_1);
        ratioLayout1 = (RatioLayout) rootView.findViewById(R.id.ratio_layout_1);
        toStartTimerLayout1 = (TimerLayout) rootView.findViewById(R.id.to_start_timer_layout_1);

        timerLayout2 = (TimerLayout) rootView.findViewById(R.id.timer_layout_2);
        ivImage2 = (ImageView) rootView.findViewById(R.id.iv_image_2);
        tvTitle2 = (TextView) rootView.findViewById(R.id.tv_title_2);
        tvNewPrice2 = (TextView) rootView.findViewById(R.id.tv_new_price_2);
        tvDeprecatePrice2 = (TextView) rootView.findViewById(R.id.tv_deprecate_price_2);
        limitLayout2 = (LinearLayout) rootView.findViewById(R.id.limit_2);
        rootState2 = (RelativeLayout) rootView.findViewById(R.id.root_state_2);
        tvState2 = (TextView) rootView.findViewById(R.id.tv_state_2);
        ratioLayout2 = (RatioLayout) rootView.findViewById(R.id.ratio_layout_2);
        toStartTimerLayout2 = (TimerLayout) rootView.findViewById(R.id.to_start_timer_layout_2);

        timerLayout3 = (TimerLayout) rootView.findViewById(R.id.timer_layout_3);
        ivImage3 = (ImageView) rootView.findViewById(R.id.iv_image_3);
        tvTitle3 = (TextView) rootView.findViewById(R.id.tv_title_3);
        tvNewPrice3 = (TextView) rootView.findViewById(R.id.tv_new_price_3);
        tvDeprecatePrice3 = (TextView) rootView.findViewById(R.id.tv_deprecate_price_3);
        limitLayout3 = (LinearLayout) rootView.findViewById(R.id.limit_3);
        rootState3 = (RelativeLayout) rootView.findViewById(R.id.root_state_3);
        tvState3 = (TextView) rootView.findViewById(R.id.tv_state_3);
        ratioLayout3 = (RatioLayout) rootView.findViewById(R.id.ratio_layout_3);
        toStartTimerLayout3 = (TimerLayout) rootView.findViewById(R.id.to_start_timer_layout_3);

        ivTitle = (ImageView) rootView.findViewById(R.id.iv_title);

        ImageLoader.loadLocalImage(mContext, ivTitle, R.mipmap.ic_home_flash_sale);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_home_flash_sale;
    }

    public void refreshUI1(Goods flashGoods) {
        ImageLoader.loadImageWithPlaceHolder(mContext, ivImage1, flashGoods.getGoodsThumb());
        tvTitle1.setText(flashGoods.getGoodsName());
        tvNewPrice1.setText(
                TextRenderUtils.getBeautyPrice(
                        flashGoods.getLimitPrice(),
                        flashGoods.getGoodsUnit(),
                        UIUtils.dp2px(16),
                        UIUtils.dp2px(14)));
        tvDeprecatePrice1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tvDeprecatePrice1.setText(
                TextRenderUtils.getBeautyPrice(
                        flashGoods.getShopPrice(),
                        flashGoods.getGoodsUnit(),
                        UIUtils.dp2px(13),
                        UIUtils.dp2px(12)));
    }

    public void refreshUI2(Goods flashGoods) {
        ImageLoader.loadImageWithPlaceHolder(mContext, ivImage2, flashGoods.getGoodsThumb());
        tvTitle2.setText(flashGoods.getGoodsName());
        tvNewPrice2.setText(
                TextRenderUtils.getBeautyPrice(
                        flashGoods.getLimitPrice(),
                        flashGoods.getGoodsUnit(),
                        UIUtils.dp2px(16),
                        UIUtils.dp2px(14)));
        tvDeprecatePrice2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tvDeprecatePrice2.setText(
                TextRenderUtils.getBeautyPrice(
                        flashGoods.getShopPrice(),
                        flashGoods.getGoodsUnit(),
                        UIUtils.dp2px(13),
                        UIUtils.dp2px(12)));
    }

    public void refreshUI3(Goods mFlashGoods3) {
        ImageLoader.loadImageWithPlaceHolder(mContext, ivImage3, mFlashGoods3.getGoodsThumb());
        tvTitle3.setText(mFlashGoods3.getGoodsName());
        tvNewPrice3.setText(
                TextRenderUtils.getBeautyPrice(
                        mFlashGoods3.getLimitPrice(),
                        mFlashGoods3.getGoodsUnit(),
                        UIUtils.dp2px(16),
                        UIUtils.dp2px(14)));
        tvDeprecatePrice3.setText(
                TextRenderUtils.getBeautyPrice(
                        mFlashGoods3.getShopPrice(),
                        mFlashGoods3.getGoodsUnit(),
                        UIUtils.dp2px(13),
                        UIUtils.dp2px(12)));
        tvDeprecatePrice3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
    }
}
